package com.zm.demo.core.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zoum
 * @create 2020/1/13 16:40
 */
public class ContainsDuplicate {


    public boolean containsDuplicate(int[] nums) {
        if(nums == null){
            return false;
        }

        Map<Integer, Integer> map = new HashMap<>(nums.length);
        return containsDuplicate(nums, 0, nums.length, map);
    }

    public boolean containsDuplicate(int[] nums, int start, int end, Map<Integer, Integer> map) {

        if (start == end || (start+1) == end){
            return map.putIfAbsent(nums[start],1) != null;
        }else {
            return containsDuplicate(nums, start, (start+end)/2, map) || containsDuplicate(nums, (start+end)/2, end, map);
        }
    }
}
